﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR91Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR91Response))]
    public class RR91ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR91Response clazz;
        
        public RR91ResponseSerializer(IRR91Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("AVVeatekst");
            if (clazz.AVVeatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AVVeatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AVVeatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veakood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Isikud");
            if (clazz.Isikud!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR91Response>Isikud>Isikud", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Isikud.Count);
                for (int x = 0; ((clazz.Isikud != null) 
                            && (x < clazz.Isikud.Count)); x = (x + 1)) {
                    if (clazz.Isikud[x]!=null) {
                        Writer.WriteStartElement("Isikud");
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                        Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                        metaIsikud.NewSerializer(clazz.Isikud[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikud");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Suhe");
            if (clazz.Suhe!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR91Response>Suhe>Suhe", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Suhe.Count);
                for (int x = 0; ((clazz.Suhe != null) 
                            && (x < clazz.Suhe.Count)); x = (x + 1)) {
                    if (clazz.Suhe[x]!=null) {
                        Writer.WriteStartElement("Suhe");
                        global::Xtee.Core.SerializationMetadata metaSuhe = this.GetMetaData(clazz.Suhe[x]);
                        Writer.WriteTypeAttribute(metaSuhe.TypeQualifiedName.Namespace, metaSuhe.TypeQualifiedName.Name);
                        metaSuhe.NewSerializer(clazz.Suhe[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Suhe");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AVVeatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR91Response>AVVeatekst");
                }
                clazz.AVVeatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AVVeatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR91Response>AVVeatekst", Reader.LocalName);
            }
            if (Reader.LocalName=="Veakood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR91Response>Veakood");
                }
                clazz.Veakood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("Veakood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR91Response>Veakood", Reader.LocalName);
            }
            if (Reader.LocalName=="Veatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR91Response>Veatekst");
                }
                clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Veatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR91Response>Veatekst", Reader.LocalName);
            }
            if (Reader.LocalName=="Isikud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR91Response>Isikud");
                }
                clazz.Isikud = new System.Collections.Generic.List<RR91Response.IIsikudType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Isikud");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Isikud")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR91Response>Isikud>Isikud");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<RR91Response.IIsikudType>(Reader, ">>>RR91Response>Isikud>Isikud", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR91Response.IIsikudType item = metaIsikud.NewEntity<RR91Response.IIsikudType>();
                        clazz.Isikud.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("Isikud");
                            metaIsikud.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR91Response>Isikud", Reader.LocalName);
            }
            if (Reader.LocalName=="Suhe") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR91Response>Suhe");
                }
                clazz.Suhe = new System.Collections.Generic.List<RR91Response.ISuheType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Suhe");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Suhe")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR91Response>Suhe>Suhe");
                        }
                        global::Xtee.Core.SerializationMetadata metaSuhe = this.GetMetaData<RR91Response.ISuheType>(Reader, ">>>RR91Response>Suhe>Suhe", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR91Response.ISuheType item = metaSuhe.NewEntity<RR91Response.ISuheType>();
                        clazz.Suhe.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("Suhe");
                            metaSuhe.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR91Response>Suhe", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR91Response>Isikud>Isikud", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR91Response.IsikudType))]
        public class IsikudTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR91Response.IIsikudType clazz;
            
            public IsikudTypeSerializer(RR91Response.IIsikudType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isikud.Isikukood");
                if (clazz.IsikudIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Eesnimi");
                if (clazz.IsikudEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Perekonnanimi");
                if (clazz.IsikudPerekonnanimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudPerekonnanimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudPerekonnanimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Synniaeg");
                if (clazz.IsikudSynniaeg!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudSynniaeg))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudSynniaeg");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Sugu");
                if (clazz.IsikudSugu!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudSugu))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudSugu");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Isikud.Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Isikud>Isikud>Isikud.Isikukood");
                    }
                    clazz.IsikudIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Isikud>Isikud>Isikud.Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Isikud>Isikud>Isikud.Eesnimi");
                    }
                    clazz.IsikudEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Isikud>Isikud>Isikud.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Perekonnanimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Isikud>Isikud>Isikud.Perekonnanimi");
                    }
                    clazz.IsikudPerekonnanimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Perekonnanimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Isikud>Isikud>Isikud.Perekonnanimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Synniaeg") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Isikud>Isikud>Isikud.Synniaeg");
                    }
                    clazz.IsikudSynniaeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Synniaeg")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Isikud>Isikud>Isikud.Synniaeg", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Sugu") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Isikud>Isikud>Isikud.Sugu");
                    }
                    clazz.IsikudSugu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Sugu")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Isikud>Isikud>Isikud.Sugu", Reader.LocalName);
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR91Response>Suhe>Suhe", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR91Response.SuheType))]
        public class SuheTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR91Response.ISuheType clazz;
            
            public SuheTypeSerializer(RR91Response.ISuheType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Suhe.Isikukood_kes");
                if (clazz.SuheIsikukoodKes!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SuheIsikukoodKes))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SuheIsikukoodKes");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Suhe.Isikukood_kelle");
                if (clazz.SuheIsikukoodKelle!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SuheIsikukoodKelle))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SuheIsikukoodKelle");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Suhe.Suhtetyyp");
                if (clazz.SuheSuhtetyyp!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SuheSuhtetyyp))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SuheSuhtetyyp");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Suhe.Isikukood_kes") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Suhe>Suhe>Suhe.Isikukood_kes");
                    }
                    clazz.SuheIsikukoodKes = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Suhe.Isikukood_kes")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Suhe>Suhe>Suhe.Isikukood_kes", Reader.LocalName);
                }
                if (Reader.LocalName=="Suhe.Isikukood_kelle") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Suhe>Suhe>Suhe.Isikukood_kelle");
                    }
                    clazz.SuheIsikukoodKelle = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Suhe.Isikukood_kelle")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Suhe>Suhe>Suhe.Isikukood_kelle", Reader.LocalName);
                }
                if (Reader.LocalName=="Suhe.Suhtetyyp") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR91Response>Suhe>Suhe>Suhe.Suhtetyyp");
                    }
                    clazz.SuheSuhtetyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Suhe.Suhtetyyp")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR91Response>Suhe>Suhe>Suhe.Suhtetyyp", Reader.LocalName);
                }
            }
        }
    }
}
